<?php 
/**************************************************/
## Class Name - Model_COUNTRY (Contains all the functions related Country modules)
## Created By - Techmodi (22/08/2011)
/**************************************************/
class Model_Budget extends Database
{	
	function Model_Budget() {	
		$this->Budget = BUDGET;		
		$this->Database();
	}
	
	// for add Budget
	function addBudget($array) {
		$this->InsertData($this->Budget, $array);
		$insertId = mysql_insert_id();
		return $insertId;
	}
	
	## List all Budget
	function getAllBudget($searchindex='',$col1='', $limit='',$offset='') {
		$fields = array('s.*');	
		$tables = array($this->Budget." AS s");

		
		
		if($searchindex != '' && $searchindex!='Budget') {
			$where = array("s.budget_name LIKE '".trim($searchindex)."'");
		}
		if($col1 =='0')
		{
			$order = array("budget_id ASC");
		}		
		if($col1 =='1')
		{
			$order = array("budget_id DESC");
		}
		
		$result1 = $this->SelectData($fields,$tables, $where, $order , $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get Budget details by Budgetid
	function getBudgetDetailsById($Budgetid) {
		$fields = array();	
		$tables = array($this->Budget);
		$result1 = $this->SelectData($fields,$tables, $where= array("budget_id=".$Budgetid), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		//print_r($result);
		return $result;
	}
	
	## Edit Country by Budgetid
	function editBudgetById($array, $Budgetid){
		$this->UpdateData($this->Budget,$array,"budget_id",$Budgetid,0);
	}
	
	## Update Budget status with multiple Budgetids
	function updateBudgetStatus($Budgetid, $status) {		
		$sql = "UPDATE ".$this->Budget." SET budget_status='".$status."' WHERE budget_id = (".$Budgetid.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Delete country with multiple Budgetids
	function deletemultipleBudgetById($Budgetids, $status) {
		$sql = "DELETE FROM ".$this->Budget." WHERE budget_id IN (".$Budgetids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete Country cat by id
	function deleteBudgetById($Budgetid){
		$this->DeleteData($this->Budget,"budget_id",$Budgetid);
	}
	
	/****************************************************/
	## Update country status with multiple Budgetids
	function updateMultipleBudgetStatus($Budgetids, $status) {
		$sql = "UPDATE ".$this->Budget." SET budget_status='".$status."' WHERE budget_id IN (".$Budgetids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete country category with multiple Budgetids
	function deleteMultipleBudget($Budgetids) {
		$sql2 = "DELETE FROM ".$this->Budget." WHERE budget_id IN (".$Budgetids.")";		
		$result1= $this->ExecuteQuery($sql2);	 
	}
	
	## List all active Budget name
	function getAllBudgetWithActiveStatus() {
		$fields = array('');	
		$tables = array($this->Budget);
		$where= array("budget_status='1'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array("budget_id ASC"), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	## List all active country name
	function getAllBudgetOnCitypage() {
		$fields = array('');	
		$tables = array($this->Budget);
		$where= array();
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	##get all the Budget written by sandeep shirsat 23 aug 2011
	function getAllBudgetByCountryId($countryid) {
		$fields = array();	
		$tables = array($this->Budget);
		$where= array("country_id=".$countryid." and budget_status='1'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit="",0,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## checking Budget name exist or not 
	function checkBudgetName($Budgetname, $id='') {
		$fields = array();	
		$tables = array($this->Budget);
		$where= array("budget_name='".$Budgetname."'");
		
		if($id != '') 
		{
			$where[] = " budget_id!=".$id;	
		}
		
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## checking Budget name exist or not 
	function checkBudgetNameByName($Budgetname) {
		$fields = array();	
		$tables = array($this->Budget);
		$where= array("budget_name  like '".$Budgetname."%'");		
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
}
?>